// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

// 云函数入口函数
exports.main = async (event, context) => {
  const db = cloud.database()
  return  await db.collection('action').get({
    createrOpenId: event.userOpenId
  })
  .then(async res => {
    let data = res.data
    for(let i = 0; i < data.length; i++) {
      await db.collection('signTable').where({
        createrOpenId: event.userOpenId,
        actionID: data[i]._id
      }).get().then(res => {
        data[i].length = res.data.length
      })
    }
    return data
  })
}